package com.rainman.simpleredis.bootstart.configuration;

import com.rainman.simpleredis.core.SimpleRedis;
import com.rainman.simpleredis.core.process_flow.SimpleProcessFlowWorkerInterface;
import com.rainman.simpleredis.core.scheduled.SimpleScheduledWorkerInterface;
import com.rainman.simpleredis.core.simplemq.SimpleMqWorkerInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class SimpleRedisInitConfiguration {

    @Autowired
    SimpleRedis simpleRedis;

    @Autowired
    List<SimpleMqWorkerInterface> simpleMqWorkerInterfaces;

    @Autowired
    List<SimpleScheduledWorkerInterface> scheduledWorkerInterfaces;

    @Autowired
    List<SimpleProcessFlowWorkerInterface> processFlowWorkerInterfaces;

    SimpleRedisInitConfiguration(SimpleRedis simpleRedis,
                    List<SimpleMqWorkerInterface> simpleMqWorkerInterfaces,
                    List<SimpleScheduledWorkerInterface> scheduledWorkerInterfaces,
                    List<SimpleProcessFlowWorkerInterface> processFlowWorkerInterfaces ){


        simpleRedis.getSimpleConfig().getMqWorkerInterfaces().addAll(simpleMqWorkerInterfaces);
        for(SimpleScheduledWorkerInterface scheduledWorkerInterface:scheduledWorkerInterfaces){

            if(scheduledWorkerInterface.key()!=null){
                simpleRedis.addSchWorker(scheduledWorkerInterface);
            }
        }

        for(SimpleProcessFlowWorkerInterface processFlowWorkerInterface:processFlowWorkerInterfaces){

            if(processFlowWorkerInterface.workType()!=null){
                simpleRedis.getSimpleConfig().getFlowWorkerInterfaceHashMap().put(processFlowWorkerInterface.workType(),
                        processFlowWorkerInterface);
            }
        }
    }




}
